using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class MenuScreen : UIScreen
{
	public InputField nameInput;

	public Button playButton;

	public Button leaderboardButton;

	public Text bestMass;

	public Text bestSurvival;

	public Text bestKill;

	public Text lastMass;

	public Text lastSurvival;

	public Text lastKill;

	public Image skinImage;

	public CanvasGroup canvasGroup;

	public GameObject startBiggerPanel;

	public Button startButton;

	public Button startBiggerButton;

	public Button skinsButton;

	public RectTransform notSoDirty;

	public RectTransform notDirty;

	private void Awake()
	{
	}

	protected override void OnEnable()
	{
		base.OnEnable();
	}

	protected override void OnDisable()
	{
		base.OnDisable();
	}

	private void AdManager_OnRewardedAdRemoved()
	{
		startBiggerPanel.SetActive(false);
		playButton.gameObject.SetActive(true);
	}


	private void Start()
	{
		leaderboardButton.onClick.AddListener(delegate
		{
			AnalyticManager.SendEvent(AnalyticManager.ShowLeaderboard);
			SocialPlatformsManager.instance.ShowLeaderboard();
		});
		skinsButton.onClick.AddListener(UIScreenController.instance.OpenSkins);
		playButton.onClick.AddListener(Handle_PlayButtonClick);
		startButton.onClick.AddListener(Handle_PlayButtonClick);
		startBiggerButton.onClick.AddListener(Handle_StartBiggerButtonClick);
		nameInput.onEndEdit.AddListener(delegate(string name)
		{
			Values.Instance.PlayerName = name;
		});
	}

	private void Handle_PlayButtonClick()
	{
		Values.Instance.PlayerName = nameInput.text;
		GameManager.Instance.StartGame();
		AnalyticManager.SendEvent(AnalyticManager.PlayButtonClicked);
	}

	private void Handle_StartBiggerButtonClick()
	{
		AnalyticManager.SendEvent(AnalyticManager.StartBiggerButtonClicked);
	}

	public override void ShowScreen()
	{

		startBiggerPanel.SetActive(false);
		playButton.gameObject.SetActive(true);
		skinImage.sprite = GameManager.Instance.FidgetStore.fidgetTypes[GameManager.Instance.SelectedSkinIndex].fidgetLevels[0];
		nameInput.text = Values.Instance.PlayerName;
		bestMass.text = ScoreManager.BestMass.ToString();
		bestKill.text = ScoreManager.BestKill.ToString();
		bestSurvival.text = ScoreManager.BestSurviveTime.ToString("0");
		lastMass.text = ScoreManager.LastMass.ToString();
		lastKill.text = ScoreManager.LastKill.ToString();
		lastSurvival.text = ScoreManager.LastSurviveTime.ToString("0");
		GameManager.Instance.LastGameLenght = 0f;
	}

	private IEnumerator PreventTouches()
	{
		canvasGroup.interactable = false;
		yield return new WaitForSecondsRealtime(2f);
		canvasGroup.interactable = true;
	}
}
